home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / PROGEDIT / 0748.ZIP / BOX < prev    next >
Text File  |  1986-12-29  |  1KB  |  60 lines

  1. #define CTRL_B          2
  2. #define CTRL_C          3
  3. #define BOXCHAR         "*"
  4.  
  5.  
  6. init()
  7. {
  8.   assign_key("box",    CTRL_B);   /* <CTRL> B */
  9.   assign_key("center", CTRL_C);   /* <CTRL> C */
  10. }
  11.  
  12. /* box() - this macro draws a comment box around a marked region */
  13. box()
  14. {
  15.   int col1, col2;      /* starting and ending columns of the marked region */
  16.   int line1, line2;    /* starting and ending lines of the marked region   */
  17.   int width;           /* number of characters across (really col2-col1+1) */
  18.  
  19.   col1 = marked_col();    col2 = currcol();
  20.   line1 = marked_line();  line2 = currlinenum();
  21.   width = col2 - col1 + 1;
  22.   goline(line1);
  23.  
  24.   insline();
  25.   setcol(col1);
  26.   insert(strcat("/", repstr(BOXCHAR, width)));
  27.   down();
  28.  
  29.   while (currlinenum() <= line2 + 1)
  30.   {
  31.     setcol(col1);
  32.     insert("*");
  33.     setcol(col2+1);
  34.     insert(BOXCHAR);
  35.     down();
  36.   }
  37.  
  38.   insline();
  39.   setcol(col1);
  40.   insert(strcat(repstr(BOXCHAR, width), "/"));
  41.   clear_mark();
  42. }
  43.  
  44.  
  45. /* This macro centers the current line */
  46. center()
  47. {
  48.   string text;
  49.  
  50.   text = currline();
  51.   gobol();         /* get rid of the characters in the line */
  52.   deleol();
  53.   ltrim(text);     /* remove leading & trailing blanks      */
  54.   rtrim(text);
  55.   setcol((80 - strlen(text)) / 2);   /* go to midway point  */
  56.   insert(text);    /* re-insert the text                    */
  57.   gobol();         /* move to the next line down            */
  58.   down();
  59. }
  60.